/*
 * Copyright (c) 2025 李伟国
 * SQL-API is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
 * KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
 * NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */
package com.moyu.sql.business.controller;

import com.moyu.sql.business.entity.MoyuSqlGroup;
import com.moyu.sql.business.service.IMoyuSqlGroupService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/moyu/sql/group")
public class MoyuSqlGroupController {

    @Resource
    private IMoyuSqlGroupService moyuSqlGroupService;

    /**
     * 获取SQL分组列表
     *
     * @return SQL分组列表
     */
    @RequestMapping("list")
    public List<MoyuSqlGroup> list() {
        return moyuSqlGroupService.list();
    }

    /**
     * 获取SQL分组详情
     *
     * @param id SQL分组ID
     * @return SQL分组详情
     */
    @RequestMapping("/{id}")
    public MoyuSqlGroup detail(@PathVariable String id) {
        return moyuSqlGroupService.getById(id);
    }

    /**
     * 保存分组
     *
     * @param moyuSqlGroup 分组信息
     * @return 保存后的分组信息
     */
    @PostMapping("")
    public MoyuSqlGroup save(@RequestBody MoyuSqlGroup moyuSqlGroup) {
        moyuSqlGroupService.saveOrUpdate(moyuSqlGroup);
        return moyuSqlGroup;
    }

    /**
     * 删除分组
     *
     * @param id 分组id
     * @return 是否删除成功
     */
    @DeleteMapping("/{id}")
    public boolean delete(@PathVariable String id) {
        return moyuSqlGroupService.removeById(id);
    }

}
